Passed
Push — main ( d53ef8...c82fb0 )
by Andrii
01:47
created

index.ts ➔ main   C

Complexity

Conditions 9

Size

Total Lines 37
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 37
rs 6.6666
c 0
b 0
f 0
cc 9
1
import { files } from "../files"
2
import {
3
  appenderSync,
4
  arr2line,
5
  createLineReader,
6
  templateLine
7
} from "../utils"
8
9
export {
10
  main,
11
  // varsMap
12
}
13
14
if (!module.parent)
15
  main()
16
17
async function main() {
18
  const templateRoot = `${__dirname}/template/`
19
  , outputRoot = `${__dirname}/output/`
20
21
  for (const id_ in files) {
22
    const {
23
      path,
24
    } = files[id_]
25
26
    if (!path)
27
      continue
28
29
    const append = appenderSync(`${outputRoot}${path}`)
30
31
    for await (const line of createLineReader(`${templateRoot}${path}`)) {
32
      const templ = templateLine<"id"|"value"|"prefix"|"postfix">(line)
33
34
      if (!templ) {
35
        await append(line, "\n")
36
        continue
37
      }
38
39
      const {
40
        indentation,
41
        id,
42
        value,
43
        prefix,
44
        postfix
45
      } = templ
46
      , valueStr = value ? `=${value}` : ""
47
48
      for (const key in files) {
49
        if (key === id)
50
          continue
51
        await append(
52
          arr2line(indentation, prefix, `${[id, key].sort().join("_OVERWRITE_")}${valueStr}`, postfix)
53
        )
54
      }
55
    }
56
  }
57
}
58